package com.csproj.siiat.base.common.util.TLMessage;

import java.net.ServerSocket;

import com.csproj.basic.domain.ElectronicLockMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigInteger;

import static com.csproj.siiat.base.common.util.TLMessage.TLMessage.*;


/**
 * Created by tyshi on 2018/9/26.
 * 
 * this is the parent class for TL messages sent from guansuo, so called TL
 * 
 */

public class TLMessageBody  {

    public final Logger logger = LoggerFactory.getLogger(TLMessageBody.class);

    public String status = "";
    public String QianYaStatus = "";
    public String SuoGanStatus = "";
    public String WaiKeStatus = "";
    public String GPSStatus = "";
    public String ShiFengStatus = "";
    public String JieFengStatus = "";
    public String KaiSuoStatus = "";
    public String GuanSuoStatus = "";
    public String NanBeiWei = "";
    public String DongXiJing = "";
    public String WeiDu = "";
    public String JingDu = "";
    public String vol = "";
    public float JIE = 1.852f;

    public String bytes2Status (byte[] b) {

        String re = bytes2String(b);
        String[] r = re.split("");
        if (r.length <16 ) {
            return re;
        } else {
            QianYaStatus = r[15];
            SuoGanStatus = r[14];
            WaiKeStatus = r[13];
            GPSStatus = r[12];
            ShiFengStatus = r[11];
            JieFengStatus = r[10];
            KaiSuoStatus = r[9];
            GuanSuoStatus = r[8];
            NanBeiWei = r[7];
            DongXiJing = r[6];
        }
        return re;

    }
    public String bytes2LocationW (byte[] b) {
        Byte d =  (Byte) b[0];
        String du = String.valueOf(d.intValue());
        byte[] f = new byte[3];
        System.arraycopy( b, 1,f ,0, f.length);
        String fen = bytes2Fen(f);
        String n = "Nan";
//        if (NanBeiWei.equals("0")) {
//            n = "Bei";
//        } else {
//            n = "Nan";
//        }
        if (NanBeiWei.equals("0")) {
            n = "";
        } else {
            n = "-";
        }
        return n+du+"."+fen;
    }
    public String bytes2LocationJ (byte[] b) {
        byte[] d = new byte[2];
        System.arraycopy( b, 0,d ,0, d.length);
        String du = bytes2IntS(d);
        byte[] f = new byte[3];
        System.arraycopy( b, 2,f ,0, f.length);
        String fen = bytes2Fen(f);
        String x = "Dong";
//        if (DongXiJing.equals("0")) {
//            x = "Dong";
//        } else {
//            x = "Xi";
//        }
        if (DongXiJing.equals("0")) {
            x = "";
        } else {
            x = "-";
        }
        return x+du+"."+fen;
    }
    public  String bytes2Vol (byte[] b) {

        String du = bytes2Int(b);
        return du;
    }
    @Override
    public String toString () {
        return "";
    }

    public ElectronicLockMessage toDomain(ElectronicLockMessage elm) {
        return elm;
    }

}
